<?php

namespace app\api\controller;

use think\Controller;
use think\Request;
use app\common\model\Order as OrderModel;

class Order extends Controller
{
    /**
     * 显示资源列表
     *
     * @return \think\Response
     */
    public function index(Request $request)
    {

    }

    /**
     * 显示创建资源表单页.
     *
     * @return \think\Response
     */
    public function create()
    {
        //
    }

    /**
     * 保存新建的资源
     *
     * @param  \think\Request  $request
     * @return \think\Response
     */
    public function save(Request $request)
    {
        $data = input('param.');
        $mp_id = get_mpid();
        $data['type'] = 'trade';
        $data['order_status'] = 0;
        $mid = get_ucuser_mid();   //获取粉丝用户mid，一个神奇的函数，没初始化过就初始化一个粉丝
        $user = get_mid_ucuser($mid);                    //获取本地存储公众号粉丝用户信息
        $data['mp_id'] = get_mpid();
        $data['mid'] = $mid;
        $data['type'] = 'trade';
        $data['order_status'] = 0;
        $data['order_id'] = get_ucuser_mid().'_'.date("YmdHis");
        $data['trans_id'] = '';
        $data['buyer_openid'] = $user['openid'];
        $data['buyer_nick'] = $user['nickname'];
        $data['receiver_city'] = 'shenzhen';
        $data['receiver_zone'] = 'nanshan';
        $data['product_sku'] = 10001;
        $data['receiver_phone'] = '0755-33942068';
        $data['order_id'] = get_ucuser_mid().'_'.date("YmdHis");
        foreach( $data as $k=>$v) {           //整理参数
            if('' == $v) unset($data[$k]);
        }

        trace($data,'提交数据');
        $oModel = model("order");
        $ret = $oModel->add_or_edit_order($data);
        $oData = $oModel->where("order_id",$ret)->find();
        return json($oData);
    }

    /**
     * 显示指定的资源
     *
     * @param  int  $id
     * @return \think\Response
     */
    public function read($id)
    {
        //
    }

    /**
     * 显示编辑资源表单页.
     *
     * @param  int  $id
     * @return \think\Response
     */
    public function edit($id)
    {
        //
    }

    /**
     * 保存更新的资源
     *
     * @param  \think\Request  $request
     * @param  int  $id
     * @return \think\Response
     */
    public function update(Request $request, $id)
    {
        //
    }

    /**
     * 删除指定资源
     *
     * @param  int  $id
     * @return \think\Response
     */
    public function delete($id)
    {
        //
    }
}
